package cn.felord.common.config;

import cn.felord.common.security.*;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

/**
 * @author Dax
 * @since 23:32  2018/9/21
 */
@Configuration
@EnableConfigurationProperties(JwtCertificateProperties.class)
public class JwtConfig {

    @Bean
    public JwtTokenGenerator jwtTokenGenerator(JwtCertificateProperties jwtCertificateProperties) {
        Assert.notNull(jwtCertificateProperties, "jwt certificate config  is null");
        return new JwtTokenGenerator(new KeyPairFactory(), jwtCertificateProperties);
    }

    @Bean
    public JwtTokenStorage jwtTokenStorage() {
        return new JwtTokenCacheStorage();
    }
}
